document.ready(function() {
    setValue('menuid', getUrlParam('menuid'));

    getSortationList();
    queryKey('ok', 'yes');
});

function getSortationList() {
    var param = {};
    param.ctrl = 'recommend';
    param.func = 'getSortationList';

    sendAjax(param, function(result) {
        loadOptionsItem('sortationOptions', 'sortationInfo', result.sortationList);
    });
}

function queryKey(flag, permission = 'no') {
    openLoad();
    resetPageBar(flag);

    var param = {};
    param.ctrl = 'recommend';
    param.func = 'getRecommendList';
    param.status = getAjaxValue('statusInfo');
    param.tabtype = getAjaxValue('tabtypeInfo');
    param.sortation = getAjaxValue('sortationInfo');
    param.page = getAjaxValue('page');
    param.menuid = getAjaxValue('menuid');
    param.permission = permission;

    sendAjax(param, function(result) {
        recommend.list = result.recommendList;

        if (result.permission != null && result.permission != '') {
            recommend.permission = result.permission;
        }
        
        loadPageBar(getValue('page'), result.allPages, result.rowCount);
        setHtml('listCount', result.listCount);

        setDisplay('mainBg', '');
        closeLoad();
    });
}

function deleteInfo(infoid) {
    setValue('tempid', infoid);
    openConfirm('确定删除吗？', tipleft, function() {
        var param = {};
        param.ctrl = 'recommend';
        param.func = 'deleteInfo';
        param.infoid = getAjaxValue('tempid');

        sendAjax(param, function(result) {
            queryKey('page');
        });
    });
}